<?php
class Shop_Form_Image_Add extends Promotor_Form_Scaffold {
	public function init() {
		$this->setMethod('post');
		$this->setAttrib('enctype', Zend_Form::ENCTYPE_MULTIPART);

		$this->addPrefixPath('Promotor_Form_Decorator_','Promotor/Form/Decorator', self::DECORATOR);
        
        $subForm = $this->_getImageForm();
        $this->addSubForm($subForm, 'imagetab');
        
		$subForm = $this->_getContentForm();
        $this->addSubForm($subForm, 'contenttab');
	}

	/**
     * @return Zend_Dojo_Form_SubForm
     */
	protected function _getImageForm() {
    	$subForm = new Zend_Form_SubForm();
        $subForm->setAttribs(array(
            'name'   => 'imagetab',
            'legend' => 'Zdięcie',
        ));
        $subForm
        	->addElement(new KontorX_Form_Element_File('image', array(
        		'label' => 'Zdięcie',
        		'required' => true,
        		'destination' => Shop_Model_Image::UPLOAD_PATH,
        		'filters' => array(
        			'UniqName' => new KontorX_Filter_File_UniqName()
        		),
        		'validators' => array(
        			'upload' => array(
        				'validator' => 'Upload'),
//        			'isImage' => array(
//        				'validator' => 'IsImage',
//        				'options' => array(
//        					'headerCheck' => true
//        				)),
//        			'mimeType' => array(
//        				'validator' => 'MimeType',
//        				'options' => array(
//        					'headerCheck' => true,
//        					'image/jpeg',
//        					'image/png',
//        					'image/gif',
//        				)
//        			),
					'extension' => array(
        				'validator' => 'Extension',
        				'options' => 'jpg,png,gif'
        			),
        			'size' => array(
        				'validator' => 'Size',
        				'options' => array(
        					'min' => '3kb',
        					'bytestring' => true)),
        			'count' => array(
        				'validator' => 'Count',
        				'options' => array(
        					'max' => 1))
        		)
        	)))
        	->addElement(new KontorX_Form_Element_Db_Select('product_id', array(
            	'label' => 'Produkt',
                'description' => 'Wybierz produktu',
            	'required' => true,
            	'tableName' => 'shop_product',
            	'tableCols' => array('key' => 'id','value' => 'name')
            )))
            ->addElement(
            	'Checkbox',
            	'main',
            	array(
            		'label' => 'Zdięcie główne',
            		'checked' => false,
            		'ignore' => true
            	)
            );
        return $subForm;
    }

	/**
     * @return Zend_Form_SubForm
     */
    protected function _getContentForm() {
    	$subForm = new Zend_Form_SubForm();
        $subForm->setAttribs(array(
            'name'   => 'contenttab',
            'legend' => 'Treść',
        ));
        $subForm
        	->addElement(
                'text',
                'name',
                array(
                    'label' => 'Nazwa zdięcia'
                )
            );

        return $subForm;
    }
}